/**
 * 项目名：化工企业安全生产信息化管理平台
 * 日期：    2020-07-26 17:45:29
 * Copyright (c) 2015- -版权所有
 */
package com.joysuch.wwyt.bp.controller;

import cn.zlg.common.springmvc.validate.constraints.NotNull;
import com.joysuch.wwyt.bp.bean.BpDeviceFacilityStopRecoverRecordEditBean;
import com.joysuch.wwyt.bp.bean.BpDeviceFacilityStopRecoverRecordListBean;
import com.joysuch.wwyt.bp.service.BpDeviceFacilityStopRecoverRecordService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

import static com.joysuch.wwyt.bp.bean.BpDeviceFacilityStopRecoverRecordListBean.SearchBpDeviceFacilityStopRecoverRecord;

@RestController
@Api(tags = "设备设施管理-停用与恢复")
@RequestMapping("/bp/device-facility-stop-recover-record")
public class BpDeviceFacilityStopRecoverRecordController {

    private static final Logger logger = LoggerFactory.getLogger(BpDeviceFacilityStopRecoverRecordController.class);

    @Autowired
    private BpDeviceFacilityStopRecoverRecordService bpDeviceFacilityStopRecoverRecordService;


    @RequestMapping("add")
    public Object add(@Valid @RequestBody BpDeviceFacilityStopRecoverRecordEditBean entity) {
        bpDeviceFacilityStopRecoverRecordService.add(entity);
        return ResultBean.success("");
    }

    /**
     * 设备批量 启停
     * @param entity
     * @return
     */
    @RequestMapping("batchAdd")
    public Object batchAdd(@Valid @RequestBody BpDeviceFacilityStopRecoverRecordEditBean entity) {
        bpDeviceFacilityStopRecoverRecordService.batchAdd(entity);
        return ResultBean.success("");
    }


    @RequestMapping("update")
    public Object update(@Valid @RequestBody BpDeviceFacilityStopRecoverRecordEditBean entity) {
        if (entity.getId() == null) {
            return ResultBean.fail(102, "未指定主键");
        }
        bpDeviceFacilityStopRecoverRecordService.update(entity);
        return ResultBean.success("");
    }


    @RequestMapping("page")
    public Object page(Pageable page, SearchBpDeviceFacilityStopRecoverRecord condition) {
        Page<BpDeviceFacilityStopRecoverRecordListBean> data = bpDeviceFacilityStopRecoverRecordService.findByPage(page, condition);
        return ResultBean.pageData(data.getContent(), data.getTotalElements());
    }


    @RequestMapping("select-page")
    public Object selectPage(Pageable page, SearchBpDeviceFacilityStopRecoverRecord condition) {
        Page<BpDeviceFacilityStopRecoverRecordListBean> data = bpDeviceFacilityStopRecoverRecordService.findByPage(page, condition);
        return ResultBean.pageData(data.getContent(), data.getTotalElements());
    }


    @RequestMapping("delete")
    public Object delete(Long id) throws Exception {
        bpDeviceFacilityStopRecoverRecordService.delete(id);
        return ResultBean.success("");
    }


    @GetMapping("get")
    public Object getById(Long id) {
        return ResultBean.success(bpDeviceFacilityStopRecoverRecordService.getById(id));
    }

    @GetMapping("/deleteById")
    @ApiOperation(value = "删除记录")
    public ResultBean deleteById(Long recordId) {
        bpDeviceFacilityStopRecoverRecordService.deleteById(recordId);
        return ResultBean.success("");
    }
}

